<?php

require_once 'common.php';

if (!$_SESSION['admin_id']) {
    die(header('location:login.php'));
}

$act = isset($_REQUEST['act']) && !empty($_REQUEST['act']) ? $_REQUEST['act'] : '';

if ($act == 'getList') {
    $page = isset($_REQUEST['page']) && !empty($_REQUEST['page']) ? $_REQUEST['page'] : 1;
    $limit = isset($_REQUEST['limit']) && !empty($_REQUEST['limit']) ? $_REQUEST['limit'] : 10;
    $limit = (($page - 1) * $limit) . ',' . $limit;
    $list = M('case_list')->limit($limit)->order('last_time desc')->select();
    foreach ($list as $key => $value) {
        $value['last_time'] = date('Y-m-d H:i:s', $value['last_time']);
        $list[$key] = $value;
    }
    returnJson(0, '成功', $list);
}

if ($act == 'sendDingdan') {
    M('case_list')->where('case_list_id = '.$_REQUEST['case_list_id'])->update(array(
        'model' => $_REQUEST['model'],
        'price' => $_REQUEST['price'],
        'order_status' => 1
    ));
    returnJson(0, '成功');
}

if ($act == 'orderSubmit') {
    M('case_list')->where('case_list_id = '.$_REQUEST['case_list_id'])->update(array(
        'order_status' => 2
    ));
    returnJson(0, '成功');
}

if ($act == 'orderCancel') {
    M('case_list')->where('case_list_id = '.$_REQUEST['case_list_id'])->update(array(
        'model' => '',
        'price' => 0,
        'order_status' => 0
    ));
    returnJson(0, '成功');
}

if ($act == 'deleteDo') {
    M('case_list')->where('case_list_id = ' . $_REQUEST['case_list_id'])->delete();
    returnJson(0, '成功');
}

display('index');